package top.sjydzq.www.controller.Mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import top.sjydzq.www.bean.Product;
import top.sjydzq.www.service.ProductService;

import java.util.List;

@Controller
public class SearchController {
    @Autowired
    private ProductService productService;

    @RequestMapping("/search")
    public String search(String keyword, Model model) {
        List<Product> products = productService.selectByName(keyword);

        model.addAttribute("keyword", keyword);
        model.addAttribute("products", products);

        return "Mall/Search/result";
    }
}
